function showEquipmentSearch() {
	window.location.href = "showEquipmentSearch.do";
}

function ajaxFindEquipmentSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxEquipmentSearchList.do",
		data : {
			deviceNum : $("#deviceNum").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listEquipmentBox").html(msg);
		}
	});
}

function ajaxShowEquipmentEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowEquipmentEdit.do",
		data:{equipmentId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 430,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveEquipment(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}


function ajaxSaveEquipment(objDialog) {
	equipmentValidate();
	if ($("#frmEquipment").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveEquipment.do",
				success: function (msg) {
					clearInput("#sltEquipment");
					showMessageDialog("保存装备信息","装备信息保存成功。",null,dialogType.info);
					ajaxFindEquipmentSearchList();
				}
		};
		$("#frmEquipment").ajaxSubmit(options);
	}
}

function ajaxShowEquipmentView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowEquipmentView.do",
		data:{equipmentId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 430,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeleteEquipmentById(id) {
	var EquipmentIds="";
	var sltKB = $("#listEquipmentList tbody input:checked").length;
	if(id==null){
		$("#listEquipmentList tbody input:checked").each(function(){ 
			EquipmentIds += $(this).val()+";";
		});
		if(sltKB == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			EquipmentIds = EquipmentIds.substring(0, EquipmentIds.length-1);
		} 
	}else{
		EquipmentIds=id;
		sltKB = 1;
	}
	if( EquipmentIds!=null){
		showMessageDialog("删除装备信息","确定要删除所选“"+sltKB+"”条装备信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteEquipmentByIds.do",
				data:{EquipmentIds:EquipmentIds},
				success:function(msg){
					ajaxFindEquipmentSearchList();
					showMessageDialog("提示","装备信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function equipmentValidate(){
	$("#frmEquipment").validate({
		errorLabelContainer: $("#infoEquipment"),
		rules : {
			equipmentName : {
				required :true				
			},
			equipmentCode : {
				required :true,
			},
			equipmentType : {
				required :true				
			},
			ownedOrganization : {
				required :true,
			},
			supervisorName : {
				required :true				
			},
			contactWay : {
				required :true,
			}
		},
		messages : {
			equipmentName : {
				required :"请输入装备名称！"
			},
			equipmentCode : {
				required :"请输入装备编号！"
			},
			equipmentType : {
				required :"请选择装备类型！"
			},
			ownedOrganization : {
				required :"请选择所属单位！"
			},
			supervisorName : {
				required :"请输入负责人！"
			},
			contactWay : {
				required :"请输入联系方式！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}